from django.http import *
from django.http import HttpResponse
from google.appengine.api import memcache
import utils

def retweet(request):
    api = utils.get_api(request)
    status = api.retweet(id=request.POST['status_id'])
    return HttpResponse("1")

def home_time_line(request):
    api = utils.get_api(request)
    if 'max_id' in request.POST:
        timeline = api.home_timeline(max_id=request.POST['max_id'])
    elif 'since_id' in request.POST:
        timeline = api.home_timeline(since_id=request.POST['since_id'])
    else:
        timeline = api.home_timeline()
    return utils.respond(request, 'ajax_timeline', {'item_list': timeline})

def add_fav(request):
    api = utils.get_api(request)
    api.create_favorite(id=request.POST['id'])
    return HttpResponse("1")

def del_fav(request):
    api = utils.get_api(request)
    api.destroy_favorite(id=request.POST['id'])
    return HttpResponse("1")

def update(request):
    api = utils.get_api(request)
    timeline = [api.update_status(status=request.POST['status'], in_reply_to_status_id=request.POST['in_reply_to'])]
    #memcache.delete('verify_cridentials')
    return utils.respond(request, 'ajax_timeline', {'item_list':timeline})

def del_status(request):
    api = utils.get_api(request)
    api.destroy_status(id=request.POST['id'])
    return HttpResponse("1")